home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / mousdm.com / MOUSDEMO.C next >
Encoding:
C/C++ Source or Header  |  1990-02-03  |  1.5 KB  |  90 lines

  1. /*  mousdemo.c  */
  2.  
  3. /*  mouse driver demo by James B. Burks (1990)  */
  4.  
  5. /*  released into the public domain by the author  */
  6.  
  7. /*  for Borland's Turbo C 2.0  */
  8.  
  9. #include    <conio.h>
  10. #include    <graphics.h>
  11. #include    <stdio.h>
  12. #include    <stdlib.h>
  13.  
  14. #include    "mousedef.h"
  15.  
  16. void    checkgraph(void)
  17.  
  18. {
  19.  
  20. /*  routine which checks the status of each graphics call and errors
  21.     if it is not successful.
  22. */
  23. int gres;
  24.  
  25. if ( (gres = graphresult()) != 0)
  26.     {
  27.     closegraph();
  28.     printf("Graphics system error # %d which is: %s\n",
  29.         gres, grapherrormsg(gres));
  30.     exit(1);
  31.     }
  32. }
  33.  
  34. main()
  35.  
  36. {
  37.  
  38. int    nb, graphmode, graphdriver = DETECT;
  39. int    bstat, x, y;
  40. char    line[60];
  41.  
  42. initgraph(&graphdriver, &graphmode, "c:\\tc");
  43. checkgraph();
  44.  
  45. outtextxy(0, 10, "Press any key to exit mouse demo.");
  46. outtextxy(0, 20, "Move mouse and/or click buttons.");
  47.  
  48. nb = m_reset();
  49.  
  50. if (nb == 0)
  51.     {
  52.     closegraph();
  53.     printf("No mouse driver loaded!\nProgram Terminated.");
  54.     exit(2);
  55.     }
  56.  
  57. m_show_cursor();
  58.  
  59. while (!kbhit())
  60.     {
  61.  
  62.     bstat = m_status(&x, &y);
  63.  
  64.     sprintf(line, "Button status: %d  X position: %d  Y position: %d",
  65.         bstat, x, y);
  66.  
  67.     m_hide_cursor();    /* must hide cursor before drawing  */
  68.  
  69.     cleardevice();        /*  erase the screen */
  70.  
  71.     outtextxy(0, 10, "Press any key to exit mouse demo.");
  72.     outtextxy(0, 20, "Move mouse and/or click buttons.");
  73.  
  74.     outtextxy(0, 30, line);
  75.  
  76.     m_show_cursor();    /*  now show the cursor again  */
  77.  
  78.     delay(500);    /*  wait 1/2 second  */
  79.  
  80.     }
  81.  
  82. getch();
  83.  
  84. closegraph();
  85. checkgraph();
  86.  
  87. }
  88.  
  89. /*  eof mousdemo.c  */
  90.